home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Tcl / Modes / scilabMode.tcl < prev    next >
Encoding:
Text File  |  2000-12-07  |  7.0 KB  |  222 lines

  1. ## -*-Tcl-*- (install)
  2.  # ###################################################################
  3.  #  Vince's Additions - an extension package for Alpha
  4.  # 
  5.  #  FILE: "scilabMode.tcl"
  6.  #                                    created: 15/4/97 {4:03:22 pm} 
  7.  #                                last update: 12/7/00 {2:28:48 PM} 
  8.  #  Author: Vince Darley
  9.  #  E-mail: <vince@santafe.edu>
  10.  #    mail: 317 Paseo de Peralta, Santa Fe, NM 87501, USA
  11.  #     www: <http://www.santafe.edu/~vince/>
  12.  #  
  13.  #  Mode for 'Scilab'
  14.  #  
  15.  # Installation:
  16.  # 
  17.  #  Requires Alpha version 7.0 or newer.  Just drop this file into
  18.  #  the Alpha:Tcl:Modes: folder, rebuild your Tcl indices (using
  19.  #  the Tcl menu which will be there when you read this file in Alpha)
  20.  #  then quit and restart Alpha.  Now any file ending in '.sci' 
  21.  #  automatically opens in Scilab mode.  You also need to paste the
  22.  #  included icon from 'newMenuIcons.rsrc' into Alpha.  If for some
  23.  #  reason you got this file without that rsrc file, then add the line
  24.  #  'set scilabMenu "Scil"' to your prefs.tcl file.  Note: the more
  25.  #  useful features of this mode are only available if you've
  26.  #  installed "Vince's Additions".
  27.  #  
  28.  #  We can't do too much exciting, since Scilab only handles an
  29.  #  'open' apple-event --- therefore it's not usefully scriptable.
  30.  #  
  31.  # Features:
  32.  # 
  33.  #  Automatically scans Scilab's 'Help' directory to pick up all
  34.  #  Scilab keywords so they can be coloured.
  35.  #  
  36.  #  Command-clicking on a keyword opens up a window with the help
  37.  #  information for that keyword (optionally this can be made to
  38.  #  open in Scilab itself)
  39.  #  
  40.  # If Vince's Additions is installed, the following features are
  41.  # also available:
  42.  # 
  43.  #  Keywords can be completed (enter the first few letters 
  44.  #  followed by 'cmd-tab')
  45.  #  
  46.  #  Function calls can be extended to list their arguments,
  47.  #  with template stops at each argument (again use cmd-tab).
  48.  #  
  49.  #  e.g. type 'sysl<cmd-tab>' and it is completed to 'syslin'
  50.  #  and immediately expanded to:
  51.  #      syslin(•<dom>,•<A>,•<B>,•<C >•<[,D [,x0] ]>)•
  52.  #  pressing tab moves from one argument to the next, highlighting
  53.  #  each argument in turn for each entry.
  54.  #  
  55.  # This file is copyright Vince Darley 1997, but freely distributable
  56.  # provided you note any modifications you make below.
  57.  # 
  58.  #  modified   by  rev reason
  59.  #  ---------- --- --- -----------
  60.  #  2000-12-07 DWH 1.0 updated help text
  61.  # ###################################################################
  62.  ##
  63.  
  64. alpha::mode Scil 1.0 scilabMenu {*.sci *.dem} scilabMenu {
  65.     addMenu scilabMenu "•283"
  66. } help {
  67.     Scilab Mode supplies a menu for easy switching to Scilab.  The mode
  68.     automatically scans Scilab's 'Help' directory to pick up all Scilab
  69.     keywords so they can be coloured.  Command-clicking on a keyword
  70.     opens up a window with the help information for that keyword
  71.     (optionally this can be made to open in Scilab itself).
  72.     
  73.     Click on this "Scilab Example.sci" link for an example syntax file.
  74. }
  75.  
  76. newPref f alphaOpensHelpFiles 1 Scil
  77. newPref v wordBreak {[\w_]+} Scil
  78. newPref v wordBreakPreface {[^_\w]} Scil
  79. newPref color stringColor green Scil
  80. newPref color commentColor red Scil
  81. newPref color keywordColor blue Scil
  82.  
  83. proc scilabMenu {} {}
  84.  
  85. Menu -n $scilabMenu -p Scil::menuProc {
  86.     "/S<U<OswitchToScilab"
  87.     "(-"
  88.     "/K<U<OopenFileInScilab"
  89.     "/K<U<O<BswitchFileToScilab"
  90.     "/C<O<UsetClipboardToExecFile"
  91.     "rebuildScilabKeywords"
  92. }
  93.  
  94.  
  95. proc Scil::menuProc {menu item} {
  96.     switch -- $item {
  97.     switchToScilab {app::launchFore SLab}
  98.     openFileInScilab {
  99.         openAndSendFile SLab
  100.     }
  101.     switchFileToScilab {
  102.         openAndSendFile SLab
  103.         killWindow
  104.     }
  105.     setClipboardToExecFile {
  106.         putScrap "exec('[win::CurrentTail]')"
  107.     }
  108.     rebuildScilabKeywords {Scil::RebuildElectrics}
  109.     }
  110. }
  111.  
  112. set completions(Scil) \
  113.   {completion::cmd completion::electric completion::word}
  114.  
  115. proc Scil::RebuildElectrics {} {
  116.     # Get keywords by looking for all help documents,
  117.     # simple but effective.  There may be a better way.
  118.     global Scilcmds PREFS Scilelectrics
  119.     set p [pwd]
  120.     set dir  [file join [file dirname [nameFromAppl SLab]] man]
  121.     cd $dir
  122.     regsub -all ".hlp" [glob *.hlp] "" Scilcmds
  123.     cd $p
  124.     set Scilcmds " ${Scilcmds} "
  125.     set fout [open [file join ${PREFS} ScilData] w]
  126.     puts $fout "set Scilcmds \{${Scilcmds}\}"
  127.     foreach f $Scilcmds {
  128.     message "scanning $f…"
  129.     set fileid [open [file join ${dir} ${f}.hlp] r]
  130.     set contents [read $fileid]
  131.     close $fileid
  132.     if [regexp "NAME\[ \r\n\t\]+${f} - (\[^\r\n\]*)\[ \r\n\t\]+CALLING SEQUENCE\[ \r\n\t\]+(${f}|\[^=\]+= *${f})(\(\[^\r\n\]+)\)\[ \r\n\t]" \
  133.       $contents "" desc "" arg] {
  134.         if [regexp  {\((.*)\)(.*)} $arg "" in after] {
  135.         if [regexp {(, *)?\[.*\]} $in brace] {
  136.             regsub {(, *)?\[.*\]} $in {◊} in
  137.             regsub -all {,} $in {•,•} in
  138.             if {$in != "◊"} {
  139.             regsub {◊} $in "••${brace}•" in
  140.             set in "(•${in})$after"
  141.             } else {
  142.             regsub {◊} $in "•${brace}•" in
  143.             set in "(${in})$after"
  144.             }
  145.         } else {
  146.             regsub -all {,} $in {•,•} in
  147.             if {$in != ""} {
  148.             set in "(•${in}•)$after"
  149.             } else {
  150.             set in "()$after"
  151.             }
  152.         }
  153.         set Scilelectrics($f) "${in}•$desc•"                
  154.         } else {
  155.         set Scilelectrics($f) "${arg}•$desc•"
  156.         }
  157.         puts $fout "set Scilelectrics($f) \{$Scilelectrics($f)\}"
  158.     }
  159.     }
  160.     close $fout
  161.     message "done"
  162.     
  163. }
  164.  
  165. ## 
  166.  # -------------------------------------------------------------------------
  167.  # 
  168.  # "Scil::DblClick" --
  169.  # 
  170.  #  Open a help file for the given command, either in Alpha or externally
  171.  #  in Scilab.
  172.  # -------------------------------------------------------------------------
  173.  ##
  174. proc Scil::DblClick {from to shift option control} {
  175.     select $from $to
  176.     set text [getSelect]
  177.     set d "[file join [file dirname [nameFromAppl SLab]] man]"
  178.     set f "[file join ${d} ${text}.hlp]"
  179.     if [file exists $f] {
  180.     global alphaOpensHelpFiles
  181.     if {$alphaOpensHelpFiles} {
  182.         file::openQuietly $f
  183.         changeMode Scil
  184.         global win::Modes
  185.         set "win::Modes($f)" "Scil"
  186.         setWinInfo read-only 1
  187.     } else {
  188.         set name [file tail [app::launchFore SLab]]
  189.         sendOpenEvent noReply $name $f
  190.     }        
  191.     } else {
  192.     alertnote "No such help file exists in Scilab's 'man' directory."
  193.     }
  194. }
  195.  
  196. proc Scil::MarkFile {} {
  197.     message "Marking File ..."
  198.     set count 0
  199.     set pos [minPos]
  200.     set pat {^(function[\t ]\[)([\t a-zA-Z0-9,]+\])([\t =]+)([-a-zA-Z0-9_%]+)([\t ]*\()}
  201.     while {![catch {search -s -f 1 -r 1 -m 0 -i 1 $pat $pos} match]} {
  202.     incr count
  203.     set posBeg [lindex $match 0]
  204.     regexp -nocase -- $pat [getText $posBeg [lindex $match 1]] \
  205.       allofit text1 text2 text3 text4
  206.     setNamedMark $text4 $posBeg $posBeg $posBeg
  207.     set pos [nextLineStart $posBeg]
  208.     }
  209.     message "This file contains $count functions."
  210. }
  211. if {[file exists [file join ${PREFS} ScilData]]} {
  212.     source [file join ${PREFS} ScilData]
  213. } else {
  214.     alertnote "The first time you use this mode I must build a command database."
  215.     if {[catch {Scil::RebuildElectrics}]} {
  216.     set Scilcmds ""
  217.     }
  218. }
  219. regModeKeywords  -e {//} -c $ScilmodeVars(commentColor) \
  220.   -k $ScilmodeVars(keywordColor)  -s $ScilmodeVars(stringColor) \
  221.   Scil $Scilcmds
  222.